/*
 * adc.h
 *
 *  Created on: 22.02.2012
 *      Author: Roma Jam
 */

#include "stm32f10x.h"

#ifndef ADC_H_
#define ADC_H_


#define SPIa                 SPI1   /* SPI pins are remapped by software */
#define SPIa_CLK             RCC_APB2Periph_SPI1
#define SPIa_GPIO            GPIOA
#define SPIa_GPIO_CLK        RCC_APB2Periph_GPIOA
#define SPIa_PIN_SCK         GPIO_Pin_5
#define SPIa_PIN_MISO        GPIO_Pin_6
#define SPIa_CS              GPIO_Pin_4

#define SPIa_CS_HI()         GPIO_SetBits(SPIa_GPIO,SPIa_CS)
#define SPIa_CS_LO()         GPIO_ResetBits(SPIa_GPIO,SPIa_CS)

#define SPIb                 SPI2   /* SPI pins are remapped by software */
#define SPIb_CLK             RCC_APB1Periph_SPI2
#define SPIb_GPIO            GPIOB
#define SPIb_GPIO_CLK        RCC_APB2Periph_GPIOB
#define SPIb_PIN_SCK         GPIO_Pin_13
#define SPIb_PIN_MISO        GPIO_Pin_14
#define SPIb_CS              GPIO_Pin_11

#define SPIb_CS_HI()         GPIO_SetBits(SPIb_GPIO,SPIb_CS)
#define SPIb_CS_LO()         GPIO_ResetBits(SPIb_GPIO,SPIb_CS)

#define Az_norm              37500
#define El_norm              28672

struct adc_var_t {
    bool Azumuth_below_0;
    bool Elevation_below_0;
};
extern adc_var_t ADC_var;

class adc_t {
private:
public:
    void Init(void);
    void GPIOs_Set(void);
    uint16_t Recieve_chann01(void);
    uint16_t Recieve_chann02(void);
    uint16_t to_AngleAZ(const uint16_t ANumber);
    uint16_t to_AAZ_Lab(const uint16_t ANumber);
    uint16_t to_MinuteAZ(const uint16_t ANumber);
    uint16_t to_AngleEL(const uint16_t ANumber);
    uint16_t to_AEL_Lab(const uint16_t ANumber);
    uint16_t to_MinuteEL(const uint16_t ANumber);
    uint16_t to_ADC_Az(uint16_t ANumber);
    uint16_t to_ADC_El(uint16_t ANumber);
    uint16_t Char_to_Uint(uint8_t Symbol);
};
extern adc_t ADC;

extern uint16_t adc01_data, adc02_data,
            adc01_angle, adc01_minute,
            adc02_angle, adc02_minute;

#endif /* ADC_H_ */
